package com.demon.mutehelper.bean

import androidx.annotation.NonNull
import androidx.databinding.BaseObservable
import androidx.databinding.Bindable
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.PrimaryKey
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import com.demon.mutehelper.BR

@Entity
class MuteRecord() : BaseObservable() {

  @PrimaryKey(autoGenerate = true) var id: Int = 0

  @get:Bindable @NonNull @ColumnInfo(name = "name") var name: String = ""
    set(value) {
      field = value
      notifyPropertyChanged(BR.name)
    }
  @get:Bindable @ColumnInfo(name = "address") var address: String? = null
    set(value) {
      field = value
      notifyPropertyChanged(BR.address)
    }
  @get:Bindable @ColumnInfo(name = "startTime") var startTime: Long? = null
    set(value) {
      field = value
      startTimeFormat = if(value == 0L) "" else SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.getDefault()).format(Date(startTime ?: 0))
      notifyPropertyChanged(BR.startTime)
    }
  @get:Bindable @ColumnInfo(name = "endTime") var endTime: Long? = null
    set(value) {
      field = value
      notifyPropertyChanged(BR.endTime)
    }
  @get:Bindable @ColumnInfo(name = "lat") var lat: Double? = null
    set(value) {
      field = value
      notifyPropertyChanged(BR.lat)
    }
  @get:Bindable @ColumnInfo(name = "lon") var lon: Double? = null
    set(value) {
      field = value
      notifyPropertyChanged(BR.lon)
    }

  @get:Bindable @Ignore var startTimeFormat: String = ""
    set(value) {
      field = value
      notifyPropertyChanged(BR.startTimeFormat)
    }

}
